package 优先算法.双指针.移动零;

import java.util.Arrays;

/**
 * 网址:https://leetcode.cn/problems/move-zeroes/
 */

public class 移动零 {
    public static void main(String[] args) { 
        Solution so = new Solution();
        int[] nums ={0,1,0,3,12};
        so.moveZeroes(nums);
        System.out.println(Arrays.toString(nums));
    }
}
class Solution {
    public void moveZeroes(int[] nums) {
        for(int cur=0,dest=-1;cur<nums.length;cur++){
            if(nums[cur]!=0){
                dest++;
                swap(nums,cur,dest);
            }
        }
    }
    public static void swap(int[] nums, int cur,int dest) {
        int temp = nums[cur];
        nums[cur] = nums[dest];
        nums[dest] = temp;
    }
}